
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spinning.Spinning.EntityModifiers;
using Microsoft.Xna.Framework;
using Spinning.Spinning.Unitity;
using Microsoft.Xna.Framework.Input.Touch;
using Spinning.Spinning.Unitity.Storage;
using Spinning.Spinning.Entity.Scenes;
using Spinning.Spinning.ScrollLayout;

namespace Spinning.Spinning.Entity
{
    class TestScene : Scene
    {
        ButtonSprite sp;
        TextEntity te;

        XmlStorage<SaveData> save;
        SaveData data;
        ScrollLayoutScene scs;


        protected override void UpdateSelf(GameTime gameTime)
        {
            base.UpdateSelf(gameTime);

            //string f = "data:" + data.I + "," + data.S + "\n";

            //foreach (string s in data.list)
            //{
            //    f += ("list:" + s + "\n");
            //}

           // if(scs!=null)
            te.Value = scs.AllItemHeight+","+ scs._scrollPositionY;

        }

        private void hold(BaseEntity e, TouchLocation touchLocation)
        {
            Vector2 pos = touchLocation.Position;
            pos = Vector2.Transform(pos, e.UnProjection);
            e.Position = pos;
        }

        public override void OnLoad()
        {
            base.OnLoad();

            sp = new ButtonSprite();
            sp.textureName = "wind";
            sp.Origin = new Vector2(0.5f);
            sp.pressTestureName = "fire";
            sp.Position = new Vector2(50, 50);
            sp.OnLoad();
            //Attach(sp);


            //TouchManager.RegisteTouchArea(sp);

            te = new TextEntity();
            ResourceManager.ContentRoot = "";
            te.fontString = "TestFont";
            te.OnLoad();
            te.Origin = new Vector2(0.5f);
            te.Position = new Vector2(300, 500);
            te.Color = Color.Red;
            te.ZIndex = Constants.debugText;
            Attach(te);

            //save = new XmlStorage<SaveData>("data.xml");
            //data = new SaveData();
            //data.I = 12345;
            //data.S = "qwert";
            //data.list = new List<string>() { "a", "asd" };
            //save.Save(data);
            //data = save.Load();

            scs = new ScrollLayoutScene();
            scs.Color = Color.Khaki;
            scs.Size = new Vector2(450);
            scs.Position = new Vector2(240, 300);
            scs.Origin = new Vector2(.5f);
            scs.OnLoad();
            //scs.Attach(sp);
            //scs.TouchManager.RegisteTouchArea(sp);
            //sp.OnHoldEvent += hold;

            for (int i = 0; i < 8; i++)
                NewMethod();

            Attach(scs);
        }

        private void NewMethod()
        {
            ScrollLayoutElement se = new ScrollLayoutElement();
            se.OnLoad();
            scs.AddItem(se);
        }

        public override Scene Clone()
        {
            Scene scene = new TestScene();
            scene.Size = new Vector2(Constants.Window_Width, Constants.Window_Height);
            scene.OnLoad();
            scene.SortChildren();
            return scene;
        }
    }
}
